﻿using WorldMapBase.Tile.Pool;

/// <summary>
/// GpuHudEntity池化生命周期
/// </summary>
/// <typeparam name="T"></typeparam>
public class GpuHudEntityPool<T> : ObjectPool<T> where T : GpuHudEntityBase, new()
{
    private int m_initCount;
    private int m_entityId;
    private GpuHudEntityType m_entityType;

    public GpuHudEntityPool(GpuHudEntityType entityType, int initCount, int capacity, int entityId) :
    base(capacity, true, 10, 10, 0)
    {
        m_initCount = initCount;
        m_entityId = entityId;
        m_entityType = entityType;
    }

    protected override T ConstructItem()
    {
        T entityBase = GpuHudEntityHelper.GetHudEntity<T>(m_entityType, m_entityId, -1);
        return entityBase;
    }

    protected override void OnGetObject(T obj)
    {
        obj.OutPool();
    }

    protected override void BeforeRecover(T obj)
    {
        obj.BackPool();
    }

    protected override void OnRemoveItem(T obj)
    {
        obj.OnShrink();
    }

    protected override void OnBeforeDestroy()
    {
        T obj = _objects.Pop();
        _count--;
        OnRemoveItem(obj);
    }
}
